import 'package:erp/data/model/process_file.dart';
import 'package:erp/data/model/process_handle.dart';
import 'package:erp/data/model/sale_project_detail.dart';
import 'package:erp/routes/app_pages.dart';
import 'package:erp/widgets/form1/field/filter_chip.dart';
import 'package:flutter/widgets.dart';
import 'package:get/get.dart';

class SaleProjectProcessDetailController extends GetxController {
  final List<FilterChipItem> docListItems = [
    FilterChipItem(label: Text('设计概算'), data: '1'),
    FilterChipItem(label: Text('施工图纸'), data: '2'),
    FilterChipItem(label: Text('总包投标报价清单'), data: '3'),
    FilterChipItem(label: Text('招标文件'), data: '4'),
    FilterChipItem(label: Text('施工量清单'), data: '5'),
    FilterChipItem(label: Text('技术要求'), data: '6'),
  ];

  // 流程信息
  Map<String, dynamic> processData = {};

  // 市场立项项目信息
  Map<String, dynamic> saleProjectData = {};

  // 项目合同信息
  List<SaleProjectDetail> saleProjectDetails = [];

  // 流程附件信息
  List<ProcessFile> processAttachmentList = [];

  // 流程节点信息
  List<ProcessHandle> handleList = [];
  List<String> docList = [];

  @override
  void onInit() {
    var data = Get.arguments['data'];
    handleList = (data['processHandleList'] as List)
        .map((e) => ProcessHandle.fromJson(e))
        // 排除开始、结束节点
        .where((element) => element.nodeCode != 'START' && element.nodeCode != 'END')
        .toList();
    processData = data['process'];
    processAttachmentList = (data['processFileList'] as List).map((e) => ProcessFile.fromJson(e)).toList();
    var object = data['object'];
    saleProjectDetails = (object['saleProjectDetailList'] as List).map((e) => SaleProjectDetail.fromJson(e)).toList();
    saleProjectData = object['saleProject'];
    saleProjectData['docList'] = (object['saleProjectDocList'] as List).map((e) => e['docCode'].toString()).toList();
    super.onInit();
  }

  void seeProjectDetail(item) {
    Get.toNamed(Routes.SALE_PROJECT_DETAILS, arguments: {'data': item.toJson(), 'readOnly': true});
  }
}
